package com.xja.controller;/**
 * @className: DataController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/18
 **/


import com.xja.pojo.ArticleData;
import com.xja.pojo.CommentData;
import com.xja.pojo.MoneyData;
import com.xja.pojo.UserData;
import com.xja.service.DataService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : DataController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/18  16:20
 */
@Controller
@RequestMapping("data")
public class DataController {
    private Logger logger = LoggerFactory.getLogger(AdminController.class);
    @Reference(url = "dubbo://localhost:20882")
    private DataService dataService;

    @RequestMapping("articleData")
    public  String articleData(Model model){
        logger.info("统计文章数据");
        List<ArticleData> dataList = dataService.getArticleData();
        List<String> str1 = new ArrayList<>();
        List<Integer> str2 = new ArrayList<>();

        for(ArticleData data:dataList){
            str1.add(data.getMonthes());
            str2.add(data.getCounts());
        }


        model.addAttribute("substr1",str1);
        model.addAttribute("substr2",str2);
        return "articleData";
    }

    @RequestMapping("commentData")
    public  String commentData(Model model){
        logger.info("统计评论数据");
        List<CommentData> dataList = dataService.getCommentData();
        List<String> str1 = new ArrayList<>();
        List<Integer> str2 = new ArrayList<>();

        for(CommentData data:dataList){
            str1.add(data.getMonthes());
            str2.add(data.getCounts());
        }


        model.addAttribute("substr1",str1);
        model.addAttribute("substr2",str2);
        return "commentData";
    }

    @RequestMapping("userData")
    public  String userData(Model model){
        logger.info("统计用户数据");
        List<UserData> dataList = dataService.getUserData();
        List<String> str1 = new ArrayList<>();
        List<Integer> str2 = new ArrayList<>();

        for(UserData data:dataList){
            str1.add(data.getMonthes());
            str2.add(data.getCounts());
        }


        model.addAttribute("substr1",str1);
        model.addAttribute("substr2",str2);
        return "userData";
    }
    @RequestMapping("moneyData")
    public  String moneyData(Model model){
        logger.info("统计收益支出数据");
        List<MoneyData> dataList = dataService.getMoneyData();
        List<String> str1 = new ArrayList<>();
        List<Integer> str2 = new ArrayList<>();
        List<Integer> str3 = new ArrayList<>();
        List<Integer> str4 = new ArrayList<>();

        for(MoneyData data:dataList){
            str1.add(data.getMonthes());
            str2.add(data.getCount1());
            str3.add(data.getCount2());
            str4.add(data.getCount3());
        }


        model.addAttribute("substr1",str1);
        model.addAttribute("substr2",str2);
        model.addAttribute("substr3",str3);
        model.addAttribute("substr4",str4);
        return "data";
    }
}
